package com.bwbear.db.splitdb.config;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author 张照威
 * @date 2020/8/20
 * @mail 865533614@qq.com
 * @describe
 */
@Component
@Slf4j
@Aspect
@Order(-1)
public class DataSourceAspect {

    /**
     * 设置切面范围
     * 例如
     * execution(* com.*.*.app.*.controller.*.*())
     *
     */
    @Pointcut("")
    public void pointCut(){

    }


    /**
     * 参数为数据库名
     */
    @Before(value = "pointCut()")
    public void doBefore(){
        DataSourceContextHolder.setDataSource("");
    }

    /**
     * 清除数据源上下文
     */
    @After("pointCut()")
    public void doAfter(){
        DataSourceContextHolder.clear();
    }
}